/*头文件包含*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/*OLED屏幕的参数像素点配置，*/
#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

/*软件模拟SPI的接口*/
// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI 9                                    //数据线
#define OLED_CLK 10                                    //时钟线
#define OLED_DC 11                                     //数据/命令标志（0，命令；1，数据）
#define OLED_CS 12                                     //片选信号
#define OLED_RESET 13                                  //复位信号
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,  //这个是软件SPI的构造函数，创建了一个Adafruit_SSD1306类，类的名字叫做display
                         OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

/*下面是硬件SPI的接口，如果需要使用硬件SPI，则将下面取消注释，注释上面软件SPI接口即可*/
/* Comment out above, uncomment this block to use hardware SPI
#define OLED_DC     6
#define OLED_CS     7
#define OLED_RESET  8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,     //这个是硬件SPI的构造函数，创建了一个Adafruit_SSD1306类，类的名字叫做display
  &SPI, OLED_DC, OLED_RESET, OLED_CS);
*/

/*
下面是一些比较基础的函数
display.clearDisplay();               //清除缓冲区函数，清屏函数
display.display();            //显示当前缓冲区内的内容
display.setTextSize(s);               //设置字体大小，参数S = 1/2/3....
display.setCursor(x,y);               //设置光标位置，参数为坐标
display.setTextColor(value);          //设置字体颜色，默认WHITE
display.steTextWrap();                //设置自动换行，参数为true或者false
display.drawBitmap(x,y,Bitmap,w,h,c); //x,y是图像的坐标，Bitmap为图像数据(可以是数组名，也可以是指针)，w,h,为图像的宽和高，c是颜色，

*/
static const unsigned char PROGMEM Bu[] = {
  0x00, 0x00, 0x7F, 0xFC, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x01, 0x00, 0x03, 0x40, 0x05, 0x20,
  0x09, 0x10, 0x11, 0x08, 0x21, 0x04, 0x41, 0x04, 0x81, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, /*"不",0*/
};
static const unsigned char PROGMEM Xiang[] = {
  0x08, 0x00, 0x08, 0xF8, 0x08, 0x88, 0x7E, 0x88, 0x08, 0xF8, 0x18, 0x88, 0x1C, 0xF8, 0x2A, 0x88,
  0x48, 0x88, 0x08, 0xF8, 0x01, 0x00, 0x08, 0x84, 0x48, 0x92, 0x48, 0x12, 0x87, 0xF0, 0x00, 0x00, /*"想",1*/
};
static const unsigned char PROGMEM Xie[] = {
  0x00, 0x00, 0x7F, 0xFE, 0x40, 0x02, 0x90, 0x04, 0x10, 0x00, 0x1F, 0xF8, 0x10, 0x00, 0x20, 0x00,
  0x3F, 0xF8, 0x00, 0x08, 0x00, 0x08, 0xFF, 0xC8, 0x00, 0x08, 0x00, 0x08, 0x00, 0x50, 0x00, 0x20, /*"写",2*/
};
static const unsigned char PROGMEM Dai[] = {
  0x08, 0x90, 0x08, 0x88, 0x08, 0x88, 0x10, 0x80, 0x10, 0xBE, 0x37, 0xC0, 0x30, 0x80, 0x50, 0x40,
  0x90, 0x40, 0x10, 0x40, 0x10, 0x20, 0x10, 0x22, 0x10, 0x12, 0x10, 0x0A, 0x10, 0x06, 0x10, 0x02, /*"代",3*/
};
static const unsigned char PROGMEM Ma[] = {
  0x00, 0x00, 0x01, 0xF8, 0xFC, 0x08, 0x10, 0x08, 0x10, 0x88, 0x20, 0x88, 0x3C, 0x88, 0x64, 0xFE,
  0x64, 0x02, 0xA4, 0x02, 0x24, 0x02, 0x25, 0xFA, 0x3C, 0x02, 0x24, 0x02, 0x20, 0x14, 0x00, 0x08, /*"码",4*/
};
static const unsigned char PROGMEM De[] = {
  0x10, 0x40, 0x10, 0x40, 0x20, 0x40, 0x7E, 0x7C, 0x42, 0x84, 0x42, 0x84, 0x43, 0x04, 0x42, 0x44,
  0x7E, 0x24, 0x42, 0x24, 0x42, 0x04, 0x42, 0x04, 0x42, 0x04, 0x7E, 0x04, 0x42, 0x28, 0x00, 0x10, /*"的",5*/
};
static const unsigned char PROGMEM Wo[] = {
  0x04, 0x40, 0x0E, 0x50, 0x78, 0x48, 0x08, 0x48, 0x08, 0x40, 0xFF, 0xFE, 0x08, 0x40, 0x08, 0x44,
  0x0A, 0x44, 0x0C, 0x48, 0x18, 0x30, 0x68, 0x22, 0x08, 0x52, 0x08, 0x8A, 0x2B, 0x06, 0x10, 0x02,
  /*"我",6*/
};

static const unsigned char PROGMEM Pic_Niu[] = {
0x30,0x00,0x00,0x18,0x70,0x00,0x00,0x1C,0x78,0x00,0x00,0x3C,0x58,0x00,0x00,0x3C,
0xCC,0x0F,0xE0,0x6C,0xE7,0x7F,0xFD,0xCC,0x63,0xF0,0x1F,0x8C,0x61,0xC0,0x07,0x0C,
0x77,0x00,0x01,0xD8,0xFE,0x00,0x00,0xFE,0xFC,0x00,0x00,0x7E,0xF8,0x00,0x00,0x2E,
0x7B,0x80,0x03,0xBC,0x33,0x80,0x03,0xB8,0x30,0x00,0x00,0x18,0x30,0x3F,0xF8,0x18,
0x33,0xFF,0xFF,0x98,0x3F,0xC0,0x07,0xF8,0x3C,0x00,0x00,0x78,0x70,0x00,0x00,0x1C,
0xE0,0x00,0x00,0x0E,0xC0,0xE0,0x0E,0x06,0x81,0xF0,0x1F,0x03,0x81,0xB0,0x1B,0x03,
0x81,0xF0,0x1E,0x03,0xC0,0x40,0x04,0x06,0xE0,0x00,0x00,0x0E,0x70,0x00,0x00,0x1C,
0x3C,0x00,0x00,0x78,0x0F,0xC0,0x07,0xE1,0x07,0xFF,0xFF,0xC3,0x06,0x3F,0xF8,0xC3,
0x0C,0x00,0x00,0x7E,0x0C,0x03,0x80,0x7C,0x0C,0x0F,0xE0,0x70,0x0C,0x0C,0x60,0x60,
0x06,0x0C,0x60,0xC0,0x07,0x0C,0x61,0xC0,0x03,0x8C,0x63,0x80,0x01,0xFC,0x7F,0x00,/*"D:\tools\Arduino\素材\牛.bmp",0*/
};



// static const unsigned char* PROGMEM Chinese[7] =
// {
// BU,Xiang,Xie,Dai,Ma,De,Wo
// }
void setup() {
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  //display.begin这个函数还有其他的参数，但是这里是C++的语法，提供的库函数里面有默认参数，所以可以不用填。默认即可。
  if (!display.begin(SSD1306_SWITCHCAPVCC)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }
  display.clearDisplay();   //清除缓存
  display.setTextColor(1);  //设置字体颜色，对于oled来说，写1是有颜色，0是没颜色
  display.setTextSize(2);   //设置字体大小，默认是1，写入2就是放大1呗，以此类推
  display.setCursor(0, 0);  //设置光标位置，后面填写地址，都是相对于光标的偏移量
  display.print("Hello");   //输出"Hello"到缓存里面,只能显示英文，中文会乱码
  display.drawBitmap(0,16,Bu,16,16,1);     //显示中文“不”
  display.drawBitmap(16,16,Xiang,16,16,1);     //显示中文“想”
  display.drawBitmap(32,16,Xie,16,16,1);     //显示中文“写”
  display.drawBitmap(48,16,Dai,16,16,1);     //显示中文“代”
  display.drawBitmap(64,16,Ma,16,16,1);     //显示中文“码”
  display.drawBitmap(80,16,De,16,16,1);     //显示中文“的”
  display.drawBitmap(96,16,Wo,16,16,1);     //显示中文“我”
  display.drawBitmap(0,32,Pic_Niu,32,40,1);     //显示图片牛

  display.display();        //显示当前缓冲区内的内容
}

void loop() {
}
